package vectorConstruction;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import myLucene.GetTime;
import myLucene.Props;
import myLucene.Searcher;
import myLucene.TfIdfOld;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

import prepro.SerializeTermsToInt;

public class VerbVectorConstruction {
	public static void main(String[] args) throws Exception {
		
		Directory iDirectory = FSDirectory.open(new File(Props.readIndexPath));
		IndexSearcher searcher = new IndexSearcher(iDirectory, true);

		IndexReader iReader = searcher.getIndexReader();
		BufferedReader br = new BufferedReader(
				new FileReader(new File(args[0])));
		long start = System.currentTimeMillis();
		Props.writeToPath = "/local/joofeit";

		// HashMap<Integer, String> intToTerms =
		// Searcher.intToTerms(termsToInt);
		String[] intToTerms = SerializeTermsToInt.deserializeArray();
		// String line = "abbrechen 10909";
		// String line ="abdingen 14233";
		// String line = "besitzen 1098004";
		// String line ="beteiligen 1119183";
		String line = "";
		while ((line = br.readLine()) != null) {
			String[] lineSplit = line.split(" ");
			boolean success1 = (new File(Props.writeToPath + "/IDF").mkdir());
			boolean success2 = (new File(Props.writeToPath + "/TF").mkdir());
			boolean success3 = (new File(Props.writeToPath + "/Dist").mkdir());
			System.out.println("Create Directory = " + success1 + " "
					+ Props.writeToPath + "/IDF");
			boolean success = (new File(Props.writeToPath + "/IDF/"
					+ lineSplit[1]).mkdir());
			if (success)
				System.out.println("Create indexDir: "
						+ (Props.writeToPath + "/IDF/" + lineSplit[0]));

			long startVerb = System.currentTimeMillis();
			System.out.println("++++++++++++++++++++++++++++++++ " + line);

			Searcher.searchVerbs(line.split(" ")[2], iReader, intToTerms);
			System.out
					.println(">>>>>>>>>>>>>>>>>>>>>>>>>>> Time needed "
							+ line
							+ " "
							+ GetTime.getDuration(startVerb, System
									.currentTimeMillis()));
		}
		br.close();
		System.out
				.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>End VerbVectorConstruction, time needed  "
						+ GetTime
								.getDuration(start, System.currentTimeMillis()));
	}

}
